package hi.system;

import hi.Connector;
import hi.KeyController;
import hi.StatusPanel;

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.IOException;

import javax.swing.JFrame;

public class SystemCursorClient {
	
    public static void main(String[] args) throws IOException, AWTException {
		
    	//Status window
		JFrame statusWindow = new JFrame("HandInterface Java System Cursor Control Client");
		statusWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		statusWindow.setBackground(Color.black);
		statusWindow.setUndecorated(true);
		
		StatusPanel statusPanel = new StatusPanel();
		statusWindow.setContentPane(statusPanel);
		statusWindow.pack();
		statusWindow.setVisible(true);        // Display the window
		
	
		KeyController keyController = new KeyController();
		statusWindow.addKeyListener(keyController); //listen for keys
		
		MouseManager mouseManager;
		//Mouse window
		MouseFrame mouseWindow = new MouseFrame("HandInterface Java System Cursor Control Client");
		mouseWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mouseWindow.addKeyListener(keyController); //listen for keys
		
		int windowWidth = 640;           // Window width in pixels
		int windowHeight = 480;          // Window height in pixels
		int windowX = 50;
		int windowY = 50;
		Rectangle mouseRect = new Rectangle(windowX, windowY, windowWidth, windowHeight);

		mouseWindow.setBounds(windowX, windowY,       // Set position
						  windowWidth, windowHeight);  // and size
		
		mouseWindow.setVisible(true);        // Display the window
		mouseManager = new MouseManager(mouseRect);
		mouseWindow.addRectangleListener(mouseManager);
		keyController.addVisibilityListener(mouseWindow); //use keyboard shortcuts to hide/show mouse range window
		keyController.addMouseActiveListener(mouseManager); //use keyboard shortcuts to enable mouse control
		mouseManager.addMouseActiveListener(statusPanel); //send mouse activation to status panel for status display
		
		Connector connector = new Connector();
		connector.addPrimaryListener(mouseManager);
		keyController.setConnector(connector);
    }


}